package com.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.dao.UserDao;
import com.model.UserVO;

public class LoginController implements Controller{
	private UserDao userDao;

	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String userName=request.getParameter("userName");
		String userPwd=request.getParameter("userPwd");
	
		Map model=new HashMap();
		UserVO userVO=userDao.selectByName(userName, userPwd);
		
		if(userVO != null){
			model.put("userVO", userVO);
			
			return new ModelAndView("WEB-INF/Main.jsp",model);
			}else{
			model.put("error", "Logon failed");
			return new ModelAndView("WEB-INF/Login.jsp",model);
			}
	}

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	
}
